package com.cheetah.controller.protobuf;

import com.cheetah.annotation.ProtobufController;
import com.cheetah.annotation.RequestMapping;
import com.cheetah.annotation.RunExecutor;
import com.cheetah.constants.ProtobufConstants;
import com.cheetah.protocol.Request;
import com.cheetah.protocol.Response;
import com.cheetah.protostuff.ProtostuffSerialization;
import com.cheetah.service.GroupService;
import com.cheetah.vo.GroupVO;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @Author Administrator
 * @Date 2020/6/30
 * @Version V1.0
 * @Description:
 **/
@Component
@ProtobufController
@Slf4j
@RunExecutor("group-executor")
public class GroupController {

    @Autowired
    private LoadBalancerClient loadBalancerClient;

    @Autowired
    private GroupService groupService;

    @RequestMapping(mapping = ProtobufConstants.CREATE_GROUP,auth = false)
    public Response createGroup(Request request, Channel channel){
        GroupVO groupVO = ProtostuffSerialization.deserialize(request.getBody(), GroupVO.class);
        groupService.createGroup(groupVO,request.getRequestHeader().getNetworkId());
        return null;
    }
}
